package com.ibeeking.gmc.global.g.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.gmc.global.g.rest.service.ITimeTaskService;
import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.gmc.global.service.common.param.TimeTaskParam;
import com.ibeeking.gmc.global.service.common.query.TimeTaskPageQuery;
import com.ibeeking.gmc.global.service.common.query.TimeTaskQuery;
import com.ibeeking.gmc.global.service.common.vo.TaskJobTypeVO;
import com.ibeeking.gmc.global.service.common.vo.TimeTaskVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/g/timeTask/v1")
public class TimeTaskController {

    @Resource
    private ITimeTaskService timeTaskServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "分页查询定时任务列表")
    @PostMapping(value = "/pageList")
    public Page<TimeTaskVO> pageList(@RequestBody TimeTaskPageQuery pageQuery) {
        return this.timeTaskServiceImpl.pageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "有效定时任务模板列表查询")
    @PostMapping(value = "/list")
    public List<TimeTaskVO> list(@RequestBody TimeTaskQuery query) {
        return timeTaskServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY,describe = "根据id查询定时任务模板")
    @PostMapping(value = "/view/{id}")
    public TimeTaskVO view(@PathVariable("id") Long id) {
        return this.timeTaskServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改定时任务模板")
    @PostMapping(value = "/modify")
    public Boolean modify(@LoginUser CurrentUser currentUser, @RequestBody @Validated(BaseValidationGroup.Update.class) TimeTaskParam param){
        return this.timeTaskServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.SAVE,describe = "新增定时任务模板")
    @PostMapping(value = "/add")
    public Boolean add(@LoginUser CurrentUser currentUser,@RequestBody @Validated(BaseValidationGroup.Insert.class) TimeTaskParam param){
        return this.timeTaskServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "定时任务发布状态")
    @PostMapping(value = "/changeStatus/{tenantId}/{status}")
    public Boolean changeStatus(@LoginUser CurrentUser currentUser, @PathVariable("tenantId") Long tenantId, @PathVariable("status") Integer status) {
        return this.timeTaskServiceImpl.changeStatus(tenantId, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL,describe = "删除定时任务模板")
    @PostMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id){
        return this.timeTaskServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "定时任务类型")
    @PostMapping(value = "/taskJobType")
    public List<TaskJobTypeVO> taskJobType() {
        return this.timeTaskServiceImpl.taskJobType();
    }

}
